package com.marktotop.controller.business;


import com.marktotop.dto.UserLoginDTO;
import com.marktotop.dto.VaccinatorLoginDTO;
import com.marktotop.entity.business.Vaccinator;
import com.marktotop.error.SystemException;
import com.marktotop.response.ResultBean;
import com.marktotop.service.IUserService;
import com.marktotop.service.IVaccinatorService;
import com.marktotop.vo.business.VaccinatorReservationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器 - 接种人管理
 * </p>
 *
 * @author MarkToTop
 * @since 2021-07-12
 */
@Api(tags = "业务模块-接种人管理接口")
@RestController
@RequestMapping("/vaccine/vaccinator")
public class VaccinatorController {

    @Autowired
    private IVaccinatorService vaccinatorService;

    @Autowired
    private IUserService userService;


    /**
     * 接种人员列表(分页)
     *
     * @return
     */
    @ApiOperation(value = "人员列表", notes = "接种人员列表(分页)，模糊查询")
    @RequestMapping(value = "/findVaccinatorList",method = RequestMethod.GET)
    @RequiresPermissions({"vaccinator:show"})
    public ResultBean findVaccinatorList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                  @RequestParam(value = "pageSize") Integer pageSize,
                                  Vaccinator vaccinator) {
        return vaccinatorService.findVaccinatorList(pageNum, pageSize, vaccinator);
    }


    /**
     * 根据 接种人id查找已预约的疫苗信息
     *
     * @param pageNum
     * @param pageSize
     * @param id
     * @return
     */
    @ApiOperation(value = "已预约疫苗列表",notes = "根据接种人id查找已预约的疫苗信息")
    @RequestMapping(value = "/getReservation/{id}",method = RequestMethod.GET)
    public ResultBean findVaccinatorReservationRecords(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                       @RequestParam(value = "pageSize") Integer pageSize,
                                                       @PathVariable Long id) {
        return vaccinatorService.findVaccinatorReservationRecords(pageNum, pageSize,id);
    }


    /**
     * 添加接种人员信息
     *
     * @param vaccinator
     * @return
     */
    @ApiOperation(value = "添加接种人",notes = "添加新的接种人信息")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @RequiresPermissions({"vaccinator:add"})
    public ResultBean addVaccinator(@RequestBody @Validated Vaccinator vaccinator) {
        if (!vaccinatorService.save(vaccinator)){
            return ResultBean.error().message("添加接种人信息失败!");
        }
        return ResultBean.ok().message("添加接种人信息成功!");
    }


    /**
     * 编辑接种人员信息
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "编辑信息",notes = "编辑接种人信息")
    @RequestMapping(value = "/edit/{id}",method = RequestMethod.GET)
    @RequiresPermissions({"vaccinator:edit"})
    public ResultBean editVaccinator(@PathVariable Long id) throws SystemException {
        Vaccinator vaccinator = vaccinatorService.editVaccinator(id);
        return ResultBean.ok().message("获取要编辑的接种人信息操作成功!").data("vaccinator",vaccinator);
    }


    /**
     * 更新接种人员信息
     *
     * @param vaccinator
     * @return
     * @throws SystemException
     */
    @ApiOperation(value = "更新信息",notes = "更新接种人信息")
    @RequestMapping(value = "/update/{id}",method = RequestMethod.PUT)
    @RequiresPermissions({"vaccinator:update"})
    public ResultBean updateVaccinator(@PathVariable Long id, @RequestBody @Validated Vaccinator vaccinator) {
        if (!vaccinatorService.updateById(vaccinator)){
            return ResultBean.error().message("更新接种人信息操作成功!");
        }
        return ResultBean.ok().message("更新接种人信息操作成功!");
    }


    /**
     * 删除接种人员信息
     *      无预约信息，不删除疫苗历史，疫苗历史会保留部分用户信息
     *
     * @param id
     * @return
     * @throws SystemException
     */
    @ApiOperation(value = "删除接种人",notes = "删除单个接种人信息")
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.DELETE)
    @RequiresPermissions({"vaccinator:delete"})
    public ResultBean delete(@PathVariable Long id) throws SystemException {
        if (!vaccinatorService.removeVaccinator(id)){
            return ResultBean.error().message("删除接种人信息失败!");
        }
        return ResultBean.ok().message("删除接种人信息成功!");
    }

}
